<template>
  <div class="order-box">
    <!-- 顶部导航 -->
    <van-nav-bar title="确定订单" left-arrow @click-left="$router.back()" />
    <!-- 选择地址 -->
    <van-cell is-link title="请添加地址" @click="addAddress" />
    <main>
      <!-- 商品列表 -->
      <van-card
        v-for="(item, index) in orderList"
        :key="index"
        :price="item.originprice"
        :title="item.proname"
        :thumb="item.img1"
      />
    </main>
    <van-submit-bar
      :price="3050"
      button-text="去支付"
      @submit="onSubmit"
      disabled
    />
  </div>
</template>

<script>
export default {
  name: "OrderPage",
  data() {
    return {
      checked: "",
      token: "",
      value: "",
      msg: "快点来看看",
      show_flag: true,
      cartList: [],
    };
  },
  created() {
    this.token = sessionStorage.getItem("token");
    let userid = sessionStorage.getItem("userid");

    this.$http({
      url: "cart/list",
      method: "post",
      headers: {
        token: this.token,
      },
      data: {
        userid,
      },
    }).then((res) => {
      if (res.data.code == "200") {
        this.show_flag = false;
        this.cartList = res.data.data;
        this.checked = res.data.data.every((item) => item.flag == true);
      }
    });
  },
  methods: {
    addAddress() {
      this.$router.push("/orderAddress");
    },
  },
  computed: {
    orderList(){
        return this.cartList.filter(item=>item.flag)
    }
  },
};
</script>

<style scoped>
.order-box {
  height: 100%;
}
main {
  height: 100%;
  background: #efefef;
}
</style>